def binaryDict(val):
    return [0,val]

nameToDict={}
def addSingle(name, number, valDict):
    nameToDict[name]={number: valDict}

addSingle('身体健康水平','Q7',{1:5, 2:4, 3:3, 4:2, 5:1})
addSingle('贷款负担','Q17' ,{2:3, 1:1, 3:4, 0:1})
addSingle('职业','Q11' ,{1:2, 2:3, 3:3, 4:4, 5:5, 6:6, 7:1, 8:3})

table={}
for name,_ in nameToDict.items():
    table[name]=[]

import pandas as pd

df = pd.read_excel('data.xlsx', sheet_name = '编码数据（线上和线下）')

def addNewScore(varDict:dict) -> None:
    newScore = 0
    for question, scoreDict in varDict.items():
        print(question, scoreDict)
        print(row[question])
        newScore += scoreDict[row[question]]
    return newScore

for index, row in df.iterrows():
    for name, dict in nameToDict.items():
        table[name].append(addNewScore(dict))

internalVar=pd.DataFrame(table)
internalVar.to_csv('个人条件.csv')